package com.solcoo.dao;

import java.sql.SQLException;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Repository;

import com.ibatis.sqlmap.client.SqlMapClient;
import com.solcoo.json.GetEmployeeOrderJson;
import com.solcoo.json.ListEmployeeJson;
import com.solcoo.json.ListEmployeeOrderJson;
import com.solcoo.pojo.Useromrela;

@Repository
public class UseromrelaDao {

	@Resource
	private SqlMapClient sqlMapClient;

	public boolean add(Useromrela ur) throws SQLException {
		sqlMapClient.insert("addUseromrela", ur);
		
		return ur.getId() != null;
	}

	public boolean disable(Long id) throws SQLException {
		return sqlMapClient.delete("disableUseromrela", id) > 0 ? true : false;
	}

	public boolean update(Useromrela ur) throws SQLException {
		return sqlMapClient.update("updateUseromrela", ur) > 0 ? true : false;
	}
	
	public Useromrela getEnabledEmployee(String employeeid) throws SQLException {
		return (Useromrela) sqlMapClient.queryForObject("getEnabledUseromrelaByEmployeeid", employeeid);
	}
	
	public Useromrela getEmployee(String employeeid) throws SQLException {
		return (Useromrela) sqlMapClient.queryForObject("getUseromrelaByEmployeeid", employeeid);
	}
	
	public Useromrela getUseromrela(Useromrela ur) throws SQLException {
		return (Useromrela) sqlMapClient.queryForObject("getUseromrela", ur);
	}

	@SuppressWarnings("unchecked")
	public List<ListEmployeeJson> getEmployeeList(String ownerid) throws SQLException {
		return sqlMapClient.queryForList("getEmployeeList", ownerid);
	}

	@SuppressWarnings("unchecked")
	public List<ListEmployeeOrderJson> getEmployeeOrderList(Map<String, Object> param) throws SQLException {
		return sqlMapClient.queryForList("getEmployeeOrderList", param);
	}

	@SuppressWarnings("unchecked")
	public List<GetEmployeeOrderJson> getEmployeeOrder(Map<String, Object> param) throws SQLException {
		return sqlMapClient.queryForList("getEmployeeOrder", param);
	}

	public boolean enable(Useromrela urExs) throws SQLException {
		return sqlMapClient.delete("enableUseromrela", urExs) > 0 ? true : false;
	}

	public ListEmployeeOrderJson getOwnerOrderSum(Map<String, Object> param) throws SQLException {
		return (ListEmployeeOrderJson)sqlMapClient.queryForObject("getOwnerOrderSum", param);
	}
	
}